package com.eshop.modules.mp.service.impl;

import java.lang.invoke.SerializedLambda;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import java.io.IOException;
import java.util.Iterator;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.eshop.utils.FileUtil;
import java.util.ArrayList;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.eshop.common.utils.QueryHelpPlus;
import com.eshop.modules.mp.service.dto.WechatTemplateDto;
import java.util.LinkedHashMap;
import java.util.List;
import com.github.pagehelper.PageInfo;
import java.util.Map;
import org.springframework.data.domain.Pageable;
import com.eshop.modules.mp.service.dto.WechatTemplateQueryCriteria;
import com.eshop.dozer.service.IGenerator;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import com.eshop.modules.mp.service.WechatTemplateService;
import com.eshop.modules.mp.domain.WechatTemplate;
import com.eshop.modules.mp.service.mapper.WechatTemplateMapper;
import com.eshop.common.service.impl.BaseServiceImpl;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = { Exception.class })
public class WechatTemplateServiceImpl extends BaseServiceImpl<WechatTemplateMapper, WechatTemplate> implements WechatTemplateService
{
    private final IGenerator generator;
    
    public Map<String, Object> queryAll(final WechatTemplateQueryCriteria criteria, final Pageable pageable) {
        this.getPage(pageable);
        final PageInfo<WechatTemplate> page = (PageInfo<WechatTemplate>)new PageInfo((List)this.queryAll(criteria));
        final Map<String, Object> map = new LinkedHashMap<String, Object>(2);
        map.put("content", this.generator.convert(page.getList(), (Class)WechatTemplateDto.class));
        map.put("totalElements", page.getTotal());
        return map;
    }
    
    public List<WechatTemplate> queryAll(final WechatTemplateQueryCriteria criteria) {
        return (List<WechatTemplate>)(this.baseMapper).selectList(QueryHelpPlus.getPredicate(WechatTemplate.class, criteria));
    }
    
    public void download(final List<WechatTemplateDto> all, final HttpServletResponse response) throws IOException {
        final List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        for (final WechatTemplateDto yxWechatTemplate : all) {
            final Map<String, Object> map = new LinkedHashMap<String, Object>();
            map.put("模板编号", yxWechatTemplate.getTempkey());
            map.put("模板名", yxWechatTemplate.getName());
            map.put("回复内容", yxWechatTemplate.getContent());
            map.put("模板ID", yxWechatTemplate.getTempid());
            map.put("添加时间", yxWechatTemplate.getAddTime());
            map.put("状态", yxWechatTemplate.getStatus());
            list.add(map);
        }
        FileUtil.downloadExcel((List)list, response);
    }
    
    public WechatTemplate findByTempkey(final String recharge_success_key) {
        return (WechatTemplate)this.getOne(Wrappers.<WechatTemplate>lambdaQuery().eq(WechatTemplate::getTempkey, recharge_success_key));
    }
    
    public WechatTemplateServiceImpl(final IGenerator generator) {
        this.generator = generator;
    }
}
